import request from '../utils/request'

// 首页 - 获取用户选择的频道
const getUserChannelListAPI = () => {
  return request({
    method: 'GET',
    url: '/v1_0/user/channels'
  })
}

// 首页 - 获取文章列表
const getArticleListAPI = ({ channelId, timestamp = Date.now() + '' }) => {
  return request({
    method: 'GET',
    url: '/v1_0/articles',
    params: {
      channel_id: channelId,
      timestamp
    }
  })
}

// 首页 - 文章 不感兴趣
const articleDislikeAPI = ({ artId }) => {
  return request({
    method: 'POST',
    url: '/v1_0/article/dislikes',
    data: {
      target: artId
    }
  })
}

// 首页 - 文章 举报
const articleReportsAPI = ({ artId, type, remark }) => {
  return request({
    method: 'POST',
    url: '/v1_0/article/reports',
    data: {
      target: artId,
      type,
      remark: type === '0' ? remark : remark || null
    }
  })
}

// 首页 - 获取 所有 频道
const getAllChannelListAPI = () => {
  return request({
    method: 'GET',
    url: '/v1_0/channels'
  })
}

// 首页 - 修改（更新） 用户 选择的 频道
const updateUserChannelListAPI = ({ channels }) => {
  return request({
    method: 'PUT',
    url: '/v1_0/user/channels',
    data: {
      channels
    }
  })
}

export {
  getUserChannelListAPI,
  getArticleListAPI,
  articleDislikeAPI,
  articleReportsAPI,
  getAllChannelListAPI,
  updateUserChannelListAPI
}
